package ncut.shumei;

import ncut.shumei.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
        try {


//            方法2-----------------------------------------------

//            ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
//            try {
//                System.out.println("=== 测试Set方法注入 ===");
//                BookService bookServiceSet = (BookService) context.getBean("bookDaoSet");
//                bookServiceSet.saveBook();
//                bookServiceSet.updateBook();
//                bookServiceSet.queryBook();
//                bookServiceSet.deleteBook();
//            } catch (Exception e) {
//                System.err.println("Set方法注入测试失败: " + e.getMessage());
//            }
//
//            try {
//                System.out.println("\n=== 测试注解注入 ===");
//                BookService bookServiceAnnotation = (BookService) context.getBean("bookServiceSet");
//                bookServiceAnnotation.saveBook();
//                bookServiceAnnotation.updateBook();
//                bookServiceAnnotation.queryBook();
//                bookServiceAnnotation.deleteBook();
//            } catch (Exception e) {
//                System.err.println("注解注入测试失败: " + e.getMessage());
//            }


//            方法2=------------------------------------------
            ApplicationContext context1 = new ClassPathXmlApplicationContext("bean.xml");


            BookService bookService = context1.getBean(BookService.class);

            // 保存
            bookService.saveBook();

            // 更新
            bookService.updateBook();

            // 查询
            bookService.queryBook();

            // 删除
            bookService.deleteBook();


            
        } catch (Exception e) {
            System.err.println("Spring容器初始化失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

